//-----------------------------------------------------------------------
// <copyright file="TerritoryService.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------	

using System;
using System.Collections;
using MyFramework;
using MIMS.WRS.Entities;
using MIMS.WRS.Data;
using MyFramework.Data;
    
namespace MIMS.WRS.Business
{   
	/// <summary>
	/// 
	/// </summary> 
    public class UnitSettingService
    {

	    #region UnitSetting

		public static void CreateUnitSetting(UnitSetting unitSetting)
		{            
			try
			{
				 UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
				unitSettingDAO.CreateUnitSetting(unitSetting);
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("BusinessCreateUnitSettingException");
			}
		}       
 

		public static void CreateUnitSettingForConPoint(UnitSetting unitSetting)
		{            
			try
			{
				UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
				unitSettingDAO.CreateUnitSettingForConPoint(unitSetting);
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("BusinessCreateUnitSettingForConPointException");
			}
		}       

		public static void UpdateUnitSettingForConPointBatch(UnitSettingCollection unitSettings, int conPointID)
		{            
			try
			{
				using (TransactionScope scope = new TransactionScope()) 
				{
					UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
					unitSettingDAO.DeleteAllUnitSettingsByConPoint(conPointID);
					foreach (UnitSetting unitSettingItem in unitSettings) 
					{
						unitSettingDAO.CreateUnitSettingForConPoint(unitSettingItem);
					}					
					scope.Complete();
				}
				
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("SR.BusinessUpdateUnitSettingForConPointBatchException", ex);
			}
		} 

        public static void UpdateUnitSetting(UnitSetting unitSetting)
        {            
            try
            {
                UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
                unitSettingDAO.UpdateUnitSetting(unitSetting);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException("BusinessUpdateUnitSettingException" );
            }
        }        

        
		public static void DeleteUnitSetting(int unitSettingID)
		{            
			try
			{
				UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
				unitSettingDAO.DeleteUnitSetting(unitSettingID);
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("BusinessDeleteUnitSettingException");
			}
		}

		public static void DeleteUnitSettingByConPoint(int conPointID, int unitSettingID)
		{            
			try
			{
				UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
				unitSettingDAO.DeleteUnitSettingByConPoint(conPointID, unitSettingID);
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("BusinessDeleteUnitSettingByConPointException");
			}
		}

		public static void DeleteAllUnitSettingsByConPoint(int conPointID)
		{            
			try
			{
				UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
				unitSettingDAO.DeleteAllUnitSettingsByConPoint(conPointID);
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("BusinessDeleteAllUnitSettingsByConPointException");
			}
		}

        public static UnitSetting GetUnitSetting(int unitSettingID)
        {            
            try
            {
				UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
				 return unitSettingDAO.GetUnitSetting(unitSettingID);                
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException("BusinessGetUnitSettingException.");
            }
        }                

		public static UnitSettingCollection GetUnitSettings()
		{
			try
			{
				UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
				return unitSettingDAO.GetUnitSettingList();    
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("BusinessGetUnitSettingsException.");
			}

		}
      

		public static UnitSettingCollection GetUnitSettingsOnly()
		{
			try
			{
				UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
				return unitSettingDAO.GetUnitSettingsOnly();    
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("BusinessGetUnitSettingsOnlyException.");
			}

		}

		public static UnitSettingCollection GetUnitSettingsOnlyByConPoint(int conPointID)
		{
			try
			{
				UnitSettingDAO unitSettingDAO = new UnitSettingDAO();
				return unitSettingDAO.GetUnitSettingsOnlyByConPoint(conPointID);
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("BusinessGetUnitSettingsOnlyByConPointException.");
			}
		}


        #endregion
    }
}